<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="角色名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入角色名称" clearable size="small" style="width: 240px"
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="角色标识" prop="code">
        <el-input v-model="queryParams.code" placeholder="请输入角色标识" clearable size="small" style="width: 240px"
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="角色状态" clearable size="small" style="width: 240px">
          <el-option v-for="dict in statusDictDatas" :key="parseInt(dict.value)" :label="dict.label" :value="parseInt(dict.value)"/>
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form> -->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['service:shop:create']">新增</el-button>
      </el-col>
     
      <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
    </el-row>

    <el-table v-loading="loading" :data="datalist">
      <el-table-column label="id" prop="id" width="120" />
      <el-table-column label="驻点名称" prop="name" width="120" />
      <el-table-column label="联系电话" prop="linkPhone" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="经度" prop="lng" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="纬度" prop="lat" :show-overflow-tooltip="true" width="150"></el-table-column>
     
      <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.createdTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['service:shop:update']">修改</el-button>
         
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['service:shop:delete']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <!-- 添加或修改角色配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="驻点名称" prop="name"> 
          <el-input v-model="form.name" placeholder="请输入驻点名称" :disabled='form.id' />
        </el-form-item>
        <el-form-item label="联系方式" prop="linkPhone">
          <el-input v-model="form.linkPhone" placeholder="请输入驻点联系方式" />
        </el-form-item>
        
        <el-form-item label="经度" prop="lng">
          <el-input v-model="form.lng" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="纬度" prop="lat">
          <el-input v-model="form.lat" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="查询经纬度" label-width="100px">
            <a href="https://jingweidu.bmcx.com/" target='_blank' style="color:#46a6ff">点我!&nbsp;查询经纬度坐标</a><br />
          <!-- <a href="https://map.yanue.net/toLatLng" target='_blank' style="color:#46a6ff">点我!&nbsp;查询经纬度坐标2</a> -->
        
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {
storeList,addShop,updatePosition,deleteShop
} from "@/api/service/shop";


export default {
  name: "ServicePlan",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 角色表格数据
      datalist: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
 
      // 是否显示弹出层（菜单权限）
    //   openMenu: false,
    //   menuExpand: false,
    //   menuNodeAll: false,
    //   deptExpand: true,
    //   deptNodeAll: false,
     
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
     
      // 表单校验
      rules: {
        name: [
          { required: true, message: "方案名称不能为空", trigger: "blur" }
        ],
        linkPhone: [
          { required: true, message: "联系方式不能为空", trigger: "blur" }
        ],
        lng: [
          { required: true, message: "经度不能为空", trigger: "blur" }
        ],
        lat: [
          { required: true, message: "纬度不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      storeList(this.queryParams).then(
        response => {
          this.datalist = response.data.records;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
   
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
   
    // 表单重置
    reset() {
      if (this.$refs.menu !== undefined) {
        this.$refs.menu.setCheckedKeys([]);
      }
    //   this.menuExpand = false;
    //   this.menuNodeAll = false;
    //   this.deptExpand = true;
    //   this.deptNodeAll = false;
      this.form = {
        id: undefined,
        name: undefined,
        linkPhone: undefined,
        lng: '',
        lat: ''
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "新增驻点";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
        this.form = row;
        this.open = true;
        this.title = "修改驻点";
    },
    
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id !== undefined) {
            updatePosition(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addShop(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      // const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除驻点:"' + row.name + '"?').then(function() {
          return deleteShop({id: row.id});
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    }
   
  }
};
</script>
